<?php
defined('_JEXEC') or die('Restricted access');
$weblinkparams = $weblinkitems['params'];
unset($weblinkitems['params']);

$count = 0;
$columnouput = false;
$column = $params->get('column');

$width = floor( 100 / $column );
$columnlimit = floor(count($weblinkitems) / $column);
if($column > count($weblinkitems)){
	$width = floor( 100 / count($weblinkitems) );
	$columnlimit = 1;
}
$modplus = count($weblinkitems) - ($columnlimit * $column);

if(!empty($weblinkparams['title'])):?><h3 class="weblinkinfo_title<?php echo $weblinkparams['suffix']; ?>"><?php echo $weblinkparams['title']; ?></h3><?php endif;?>
<table class="weblinkinfo<?php echo $weblinkparams['suffix']; ?>" width="100%">
<tr>
<?php for($i=0; $i < count($weblinkitems); $i++) :
		$links = $weblinkitems[$i];
		$hits = '';
		if($weblinkparams['hit']){
			$hits = '<small>&nbsp;('. $links->hits. ')</small>';
		}
		?>
		<?php if(!$columnouput):$columnouput = true;?>
	<td width="<?php echo $width;?>%" valign="top">
	<ul>
		<?php endif;
		$totaloutput = $columnlimit;
		if($modplus > 0 && $count == ($columnlimit - 1)){
			$totaloutput++;
			$modplus--;
		}
		?>
		<li>
		<a href="<?php echo $links->link; ?>" title="<?php echo $links->title; ?>" target="<?php echo $weblinkparams['target']; ?>">
		<?php echo (isset($links->thumbnail)? $links->thumbnail: ''). $links->title. $hits; ?>
		</a>
		<?php if($weblinkparams['showdesc'] && !empty($links->description)):?>
			<br /><small><?php echo $links->description;?></small>
		<?php endif;?>
       		 </li>
 		<?php
		$count++;
		if($count >= $totaloutput):
			$columnouput = false;
			$count = 0;
		?>
	</ul>
	</td>
		<?php endif;?>
<?php endfor; ?>
</tr>
</table>
<?php
unset($weblinkparams);
unset($weblinkitems);